package com.learn.security.modules.user.controller;


import com.learn.security.modules.security.SecurityUtils;
import com.learn.security.modules.user.entity.UserInfo;
import com.learn.security.modules.user.service.IUserInfoService;
import com.learn.security.modules.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 登录用户 前端控制器
 * </p>
 *
 * @author lee
 * @since 2020-09-01
 */
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    private IUserInfoService userInfoService;


    @RequestMapping("/update")
    public R updateInfo(@RequestBody UserInfo userinfo){
        Long id = SecurityUtils.getUser().getId();//1301065962105016321L;//
        userinfo.setId(id);
        userInfoService.saveOrUpdate(userinfo);
        return R.ok();
    }
    @RequestMapping("/getInfo")
    public R getInfo(){
        Long id = SecurityUtils.getUser().getId();//1301065962105016321L;//
        UserInfo us = userInfoService.getById(id);
        return R.ok().put("info", us);
    }
}

